// $ANTLR 3.0.1 C:\\Documents and Settings\\Derek\\workspace\\cs214\\CS 214 Interpreters\\src\\edu\\calvin\\djs32\\cs214\\interpreters\\frontend\\Hobbes2008TIRBuilder.g 2008-02-25 22:18:16

package edu.calvin.djs32.cs214.interpreters.frontend;
import edu.calvin.cs214.hobbes2008.*;


import org.antlr.runtime.*;
import org.antlr.runtime.tree.*;import java.util.Stack;
import java.util.List;
import java.util.ArrayList;

@SuppressWarnings("all")
public class Hobbes2008TIRBuilder extends TreeParser {
    public static final String[] tokenNames = new String[] {
        "<invalid>", "<EOR>", "<DOWN>", "<UP>", "TUPLE", "NUMBER", "HEXDIGIT", "SIGN", "INTEGER", "WHITESPACE", "COMMENTS", "STRING", "COMMA", "LPAREN", "RPAREN"
    };
    public static final int COMMA=12;
    public static final int INTEGER=8;
    public static final int HEXDIGIT=6;
    public static final int EOF=-1;
    public static final int NUMBER=5;
    public static final int STRING=11;
    public static final int RPAREN=14;
    public static final int SIGN=7;
    public static final int LPAREN=13;
    public static final int TUPLE=4;
    public static final int COMMENTS=10;
    public static final int WHITESPACE=9;

        public Hobbes2008TIRBuilder(TreeNodeStream input) {
            super(input);
        }
        

    public String[] getTokenNames() { return tokenNames; }
    public String getGrammarFileName() { return "C:\\Documents and Settings\\Derek\\workspace\\cs214\\CS 214 Interpreters\\src\\edu\\calvin\\djs32\\cs214\\interpreters\\frontend\\Hobbes2008TIRBuilder.g"; }

     
      protected void mismatch(IntStream input, int ttype, BitSet follow) 
        throws RecognitionException { 
        throw new MismatchedTokenException(ttype, input); 
      } 
      public void recoverFromMismatchedSet(IntStream input, RecognitionException e, BitSet follow) 
        throws RecognitionException { 
        throw e; 
      } 



    // $ANTLR start expression
    // C:\\Documents and Settings\\Derek\\workspace\\cs214\\CS 214 Interpreters\\src\\edu\\calvin\\djs32\\cs214\\interpreters\\frontend\\Hobbes2008TIRBuilder.g:30:1: expression returns [HobbesTIR tir] : ( INTEGER | STRING | ^( TUPLE (ex= expression )* ) );
    public final HobbesTIR expression() throws RecognitionException {
        HobbesTIR tir = null;

        CommonTree INTEGER1=null;
        CommonTree STRING2=null;
        HobbesTIR ex = null;


        
                List expressions = new ArrayList<HobbesTIR>();

        try {
            // C:\\Documents and Settings\\Derek\\workspace\\cs214\\CS 214 Interpreters\\src\\edu\\calvin\\djs32\\cs214\\interpreters\\frontend\\Hobbes2008TIRBuilder.g:34:9: ( INTEGER | STRING | ^( TUPLE (ex= expression )* ) )
            int alt2=3;
            switch ( input.LA(1) ) {
            case INTEGER:
                {
                alt2=1;
                }
                break;
            case STRING:
                {
                alt2=2;
                }
                break;
            case TUPLE:
                {
                alt2=3;
                }
                break;
            default:
                NoViableAltException nvae =
                    new NoViableAltException("30:1: expression returns [HobbesTIR tir] : ( INTEGER | STRING | ^( TUPLE (ex= expression )* ) );", 2, 0, input);

                throw nvae;
            }

            switch (alt2) {
                case 1 :
                    // C:\\Documents and Settings\\Derek\\workspace\\cs214\\CS 214 Interpreters\\src\\edu\\calvin\\djs32\\cs214\\interpreters\\frontend\\Hobbes2008TIRBuilder.g:34:11: INTEGER
                    {
                    INTEGER1=(CommonTree)input.LT(1);
                    match(input,INTEGER,FOLLOW_INTEGER_in_expression85); 
                     tir = new IntegerTIR(Integer.decode(INTEGER1.getText())); 

                    }
                    break;
                case 2 :
                    // C:\\Documents and Settings\\Derek\\workspace\\cs214\\CS 214 Interpreters\\src\\edu\\calvin\\djs32\\cs214\\interpreters\\frontend\\Hobbes2008TIRBuilder.g:35:11: STRING
                    {
                    STRING2=(CommonTree)input.LT(1);
                    match(input,STRING,FOLLOW_STRING_in_expression99); 
                     tir = new StringTIR(STRING2.getText().substring(1, (STRING2.getText().length()-1))); 

                    }
                    break;
                case 3 :
                    // C:\\Documents and Settings\\Derek\\workspace\\cs214\\CS 214 Interpreters\\src\\edu\\calvin\\djs32\\cs214\\interpreters\\frontend\\Hobbes2008TIRBuilder.g:36:11: ^( TUPLE (ex= expression )* )
                    {
                    match(input,TUPLE,FOLLOW_TUPLE_in_expression114); 

                    if ( input.LA(1)==Token.DOWN ) {
                        match(input, Token.DOWN, null); 
                        // C:\\Documents and Settings\\Derek\\workspace\\cs214\\CS 214 Interpreters\\src\\edu\\calvin\\djs32\\cs214\\interpreters\\frontend\\Hobbes2008TIRBuilder.g:36:19: (ex= expression )*
                        loop1:
                        do {
                            int alt1=2;
                            int LA1_0 = input.LA(1);

                            if ( (LA1_0==TUPLE||LA1_0==INTEGER||LA1_0==STRING) ) {
                                alt1=1;
                            }


                            switch (alt1) {
                        	case 1 :
                        	    // C:\\Documents and Settings\\Derek\\workspace\\cs214\\CS 214 Interpreters\\src\\edu\\calvin\\djs32\\cs214\\interpreters\\frontend\\Hobbes2008TIRBuilder.g:36:21: ex= expression
                        	    {
                        	    pushFollow(FOLLOW_expression_in_expression120);
                        	    ex=expression();
                        	    _fsp--;

                        	     expressions.add(ex); 

                        	    }
                        	    break;

                        	default :
                        	    break loop1;
                            }
                        } while (true);


                        match(input, Token.UP, null); 
                    }
                     tir = new TupleTIR(expressions); 

                    }
                    break;

            }
        }
         
          catch (RecognitionException e) { 
            throw e; 
          } 
        finally {
        }
        return tir;
    }
    // $ANTLR end expression


 

    public static final BitSet FOLLOW_INTEGER_in_expression85 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_STRING_in_expression99 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_TUPLE_in_expression114 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_expression_in_expression120 = new BitSet(new long[]{0x0000000000000918L});

}